<!doctype html>
<html>
<head>
    <include file="public/head"/>
    <title>添加模型</title>
    <meta name="description" content="添加模型">
    <meta name="keywords" content="添加模型">
</head>
<body>
<div class="wrap js-check-wrap">
    <ul class="nav nav-tabs">
        <li><a href="{:cmf_plugin_url('QbtCustomModel://AdminIndex/index')}">模型管理</a></li>
        <li class="active"><a>添加模型</a></li>
    </ul>
    <form method="post" class="form-horizontal js-ajax-form margin-top-20"
          action="{:cmf_plugin_url('QbtCustomModel://AdminQbtCustomModel/addPost')}">

        <div class="form-group">
            <label class="col-sm-2 control-label"><span class="form-required">*</span>模型名称</label>
            <div class="col-md-6 col-sm-10">
                <input type="text" class="form-control" name="model_name" value="">
            </div>
        </div>
        <div class="form-group">
            <label class="col-sm-2 control-label"><span class="form-required">*</span>数据表</label>
            <div class="col-md-6 col-sm-10">
                <select name="type"  class="form-control" onchange="table_new($(this))">
                    <option value="0">请选择</option>
                    <option value="1">新建表</option>
                    <option value="2">选择已有的表</option>
                </select>
            </div>
        </div>
        <div class="form-group" id="new" style="display: none">
            <label class="col-sm-2 control-label"><span class="form-required">*</span>表名</label>
            <div class="col-md-6 col-sm-10">
                <input type="text" class="form-control" name="model_tabname" id="model_tabname" value="" placeholder="请输入表名">
            </div>
        </div>
        <div class="form-group" id="new_tab" style="display: none">
            <label class="col-sm-2 control-label"><span class="form-required">*</span>表名</label>
            <div class="col-md-6 col-sm-10">
                <select name="model_tabname" id="sel_model_tabname" class="form-control">
                    <option value="0">请选择</option>
                    <volist name="database" id="tab_val">
                        <option value="{$tab_val}">{$tab_val}</option>
                    </volist>

                </select>
            </div>
        </div>
		<div class="form-group">
			<label for="input-controller" class="col-sm-2 control-label"><span class="form-required">*</span>控制器</label>
			<div class="col-md-6 col-sm-10">
				<input type="text" class="form-control" id="input-controller" name="model_controller">
			</div>
		</div>
        <div class="form-group">
            <label class="col-sm-2 control-label">类型</label>
            <div class="col-md-6 col-sm-10">
                <select class="form-control valid" name="distinguish" id="input" aria-invalid="false">
                    <option value="1">分类模型</option>
                    <option value="2">信息模型</option>
                </select>
            </div>
        </div>
        <div class="form-group" id="new_default_field" style="display: none">
            <label class="col-sm-2 control-label">是否添加默认字段</label>
            <div class="col-md-6 col-sm-10">
                <select class="form-control valid"  id="is_default_field" name="is_default_field" id="input-" aria-invalid="false">
                    <option value="1">是</option>
                    <option value="2">否</option>
                </select>
            </div>
        </div>
        <div class="form-group">
            <label class="col-sm-2 control-label">描述</label>
            <div class="col-md-6 col-sm-10">
                <textarea name="model_description" class="form-control"></textarea>
            </div>
        </div>
        <div class="form-group">
            <label class="col-sm-2 control-label">是否启用</label>
            <div class="col-md-6 col-sm-10">
                <select class="form-control valid" name="model_status" id="input-status" aria-invalid="false">
                    <option value="1">启用</option>
                    <option value="0">禁用</option>
                </select>
            </div>
        </div>

        <div class="col-sm-offset-2 col-sm-10">
            <button type="submit" class="btn btn-primary js-ajax-submit">{:lang("SAVE")}</button>
        </div>
    </form>
</div>
<include file="public/scripts"/>
</body>
<script type="text/javascript">
    function table_new(obj) {
            var type = obj.find('option:selected').val();
            if(type==1){
                $('#new').show();
                $('#new_tab').hide();
                $('#sel_model_tabname').attr('disabled','disabled')
                $('#model_tabname').removeAttr('disabled')
                $('#new_default_field').show();
            }else if(type==2){
                $('#new').hide();
                $('#new_tab').show();
                $('#model_tabname').attr('disabled','disabled');
                $('#sel_model_tabname').removeAttr('disabled');
                $('#new_default_field').hide();
                $('#is_default_field').attr('disabled','disabled');
            }else{
                $('#new').hide();
                $('#new_tab').hide();
                $('#new_default_field').hide();
            }
    }
</script>
</html>